package xyz.scootaloo.oj.offer

import org.junit.Test
import xyz.scootaloo.console.app.support.Tester
import xyz.scootaloo.oj.ds.TreeNode
import xyz.scootaloo.oj.ds.helper.CollectionBuilder

/**
 * @author flutterdash@qq.com
 * @since 2021/4/11 14:21
 */
class P28 {

    private fun isSymmetric(root: TreeNode?): Boolean {
        if (root == null)
            return true
        return compare(root.left, root.right)
    }

    private fun compare(nodeA: TreeNode?, nodeB: TreeNode?): Boolean {
        if (nodeB == null && nodeA == null)
            return true
        if (nodeA == null || nodeB == null)
            return false
        if (nodeA.`val` != nodeB.`val`)
            return false
        return compare(nodeA.left, nodeB.right) && compare(nodeA.right, nodeB.left)
    }

    @Test
    fun test0() {
        val node = CollectionBuilder.initTree()
            .setRoot(1)
            .addLevel(2, 2)
            .addLevel(3, 4, 4, 3).build()
        println(isSymmetric(node))
    }

}
